﻿using System;
using System.Windows.Forms;
using DataLayer;
using DataLayer.Class;
using System.Collections;


namespace WinProgProject2
{
    public partial class Login : Form
    {

        public static string yetki;
        public Login()
        {
            InitializeComponent();
        }

        private void btnGiris_Click(object sender, EventArgs e)
        {
            Kullanici girilenKullanici = new Kullanici(Convert.ToInt32(txtKKodu.Text),txtSifre.Text);

            ArrayList al = KullaniciDB.girisKontrol(girilenKullanici.KullaniciNo, girilenKullanici.Sifre);
            Kullanici k =null;

            if(al.Count > 0)
             k = al[0] as Kullanici;

            if (k != null && k.KullaniciNo == girilenKullanici.KullaniciNo)
            {
                Session.kullaniciKodu = k.KullaniciNo;
                Session.yetkiler = k.yetkileriBelirle();
                
                this.Close();
                this.Dispose();
            }
            else
            {
                lblGirisHatali.Visible = true;
            }
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private void btnGirisIptal_Click(object sender, EventArgs e)
        {
            Program.loginCancel = true;
            Application.Exit();
            
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (txtSifre.Text.Length > 0)
                txtSifre.Text = txtSifre.Text.Substring(0,txtSifre.Text.Length-1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "1";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "2";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "3";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "4";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "5";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "6";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "7";
        }

        private void button8_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "8";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "9";
        }

        private void button10_Click(object sender, EventArgs e)
        {
            txtSifre.Text += "0";
        }
    }
}
